========================================================================= 
Log Path: ./log/pgms_matching_log.log 
Program Path: /Users/benjaminleo/Downloads/PGMs_and_CW_onset_Empirics/PGMs & CCs Matching Analysis.R 
Working Directory: /Users/benjaminleo/Downloads/PGMs_and_CW_onset_Empirics 
User Name: benjaminleo 
R Version: 4.3.1 (2023-06-16) 
Machine: Benjamins-MacBook-Air-4.local arm64 
Operating System: Darwin 24.2.0 Darwin Kernel Version 24.2.0: Fri Dec 6 18:40:14 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T8103 
Base Packages: stats graphics grDevices utils datasets methods base 
Other Packages: maps_3.4.2 janitor_2.2.0 wbstats_1.0.4 stevemisc_1.6.0 peacesciencer_1.1.0 bit_4.0.5 dataverse_0.3.13 countrycode_1.5.0 logr_1.3.8 common_1.1.3 foreign_0.8-86 texreg_1.39.3 margins_0.3.26 haven_2.5.4 MatchIt_4.5.5 BalanceCheck_0.2 optmatch_0.10.7 lubridate_1.9.3 forcats_1.0.0 stringr_1.5.0 dplyr_1.1.4 purrr_1.0.2 readr_2.1.4 tidyr_1.3.1 tibble_3.2.1 ggplot2_3.5.0 tidyverse_2.0.0 fcuk_0.1.21 
Log Start Time: 2025-01-15 10:16:07.203294 
========================================================================= 

> setwd("/Users/benjaminleo/Downloads/PGMs_and_CW_onset_Empirics")
> 
> 
> # PGMs and CCs Matching Analysis  -----------------------------------------
>   #This file is for rerunning my analyses using matching techniques 
> 
> #Full data created in separate do file 
> load("/Users/benjaminleo/Downloads/PGMs_and_CW_onset_Empirics795_cleaned_data.Rdata")
> View(full_data)
> 
> library(tidyverse)
> library(optmatch)  
> library(BalanceCheck)
> library(MatchIt)
> library(haven)
> library(margins)
> library(texreg)
> 
> 
> 
> # Creating the Matched Data  ----------------------------------------------
> 
> match_data <- full_data
> #defining relevant variables 
> matching_vars <- c( "cw_onset",
>                     "lag_presence",
>                     "lag_count",
>                     "lag_govt_pgm",
>                     "lag_not_govt_pgm",
>                     "lag_govt_pgm_count",
>                     "lag_not_govt_pgm_count",
>                     "v2x_polyarchy",
>                     "v2x_polyarchy",
>                     "gdppc",
>                     "log_milex",
>                     "log_rents",
>                     "pop",
>                     "rugged",
>                     "total_size",
>                     "peace_years",
>                     "post_cw",
>                     "continent")
> match_data <- match_data[complete.cases(match_data[, matching_vars]), ]
> rm(matching_vars)
> 
> #nearest neighbor matching 
> 
> # Nearest Neighbor Matching  ----------------------------------------------
> 
> #presence model 
> matched_1 <- matchit(lag_presence ~ v2x_polyarchy +
>                        gdppc +
>                        log_milex +
>                        log_rents +
>                        rugged +
>                        total_size +
>                        peace_years +
>                        post_cw,
>                      data = match_data,
>                      method = "nearest",
>                      distance = "mahalanobis")
> summary(matched_1)
> 
> 
> matched_1_data <- match.data(matched_1)
> 
> match_model_1 <- glm(cw_onset ~ lag_presence,
>                      data = matched_1_data,
>                      weights = weights)
> 
> texreg::screenreg(match_model_1)
> 
> # Calculate predicted probabilities
> pred_probs <- predict(match_model_1)
> 
> # Calculate predicted change in probability for lag_presence
> pr_change1 <- margins(match_model_1, variables = "lag_presence")
> 
> # Print results
> summary(pr_change1)
> 
> 
> #govt pgms 
> matched_2 <- matchit(lag_govt_pgm ~ v2x_polyarchy +
>                        gdppc +
>                        log_milex +
>                        log_rents +
>                        rugged +
>                        total_size +
>                        peace_years +
>                        post_cw,
>                      data = match_data,
>                      method = "nearest",
>                      distance = "mahalanobis")
> 
> summary(matched_2)
> 
> matched_2_data <- match.data(matched_2)
> 
> match_model_2 <- glm(cw_onset ~ lag_govt_pgm, 
>                      data = matched_2_data,
>                      weights = weights)
> 
> texreg::screenreg(match_model_2)
> 
> 
> 
> 
> #Non govt PGM 
> matched_3 <- matchit(lag_not_govt_pgm ~ v2x_polyarchy +
>                        gdppc +
>                        log_milex +
>                        log_rents +
>                        rugged +
>                        total_size +
>                        peace_years +
>                        post_cw,
>                      data = match_data,
>                      method = "nearest",
>                      distance = "mahalanobis")
> 
> 
> summary(matched_3)
> 
> matched_3_data <- match.data(matched_3)
> 
> match_model_3 <- glm(cw_onset ~ lag_not_govt_pgm, 
>                      data = matched_3_data,
>                      weights = weights)
> 
> texreg::screenreg(match_model_3)
> 
> # Calculate predicted probabilities
> pred_probs3 <- predict(match_model_3, type = "response")
> 
> # Calculate predicted change in probability for lag_presence
> pr_change3 <- margins(match_model_3, variables = "lag_not_govt_pgm")
> 
> # Print results
> summary(pr_change3)
> 
> 
> #Creating tables from the matching analysis
> 
> match_model_list_1 <- list(
>   match_model_1,
>   match_model_2,
>   match_model_3
> )
> 
> htmlreg(match_model_list_1,
>         custom.model.names = c("Model 1", "Model 2", "Model 3"),
>         custom.coef.names = c("intercept",
>                               "PGM Presence (t-1)",
>                               "Gov't Formed PGM Presence (t-1)",
>                               "Non-Gov't PGM Presence (t-1)"),
>         custom.coef.map = list(
>           "lag_presence" = "PGM Presence (t-1)",
>           "lag_govt_pgm" = "Gov't Formed PGM Presence (t-1)",
>           "lag_not_govt_pgm" = "Non-Gov't PGM Presence (t-1)"),
>         custom.note = "Note: The Dependent Variable for Each Model is Civil Conflict Onset, 
>         Observations are weighted by propensity scores",
>         intercept = FALSE, 
>         file = "pgm_cw_matching_nn.html",
>         color = "black",
>         caption = "",
>         digits = 3
> )
> 
> # Full Matching  ----------------------------------------------------------
> 
> 
> #presence model 
> matched_1b <- matchit(lag_presence ~ v2x_polyarchy +
>                         gdppc +
>                         log_milex +
>                         log_rents +
>                         rugged +
>                         total_size +
>                         peace_years +
>                         post_cw,
>                       data = match_data,
>                       method = "full")
> summary(matched_1b)
> 
> matched_1b_data <- match.data(matched_1b)
> 
> match_model_1b <- glm(cw_onset ~ lag_presence, 
>                       data = matched_1b_data,
>                       weights = weights)
> 
> texreg::screenreg(match_model_1b)
> 
> # Calculate predicted probabilities
> pred_probs1b <- predict(match_model_1b, type = "response")
> 
> # Calculate predicted change in probability for lag_presence
> pr_change1b <- margins(match_model_1b, variables = "lag_presence")
> 
> # Print results
> summary(pr_change1b)
> 
> 
> #govt pgms 
> matched_2b <- matchit(lag_govt_pgm ~ v2x_polyarchy +
>                         gdppc +
>                         log_milex +
>                         log_rents +
>                         rugged +
>                         total_size +
>                         peace_years +
>                         post_cw,
>                       data = match_data,
>                       method = "full")
> 
> summary(matched_2b)
> 
> matched_2b_data <- match.data(matched_2b)
> 
> match_model_2b <- glm(cw_onset ~ lag_govt_pgm, 
>                       data = matched_2b_data,
>                       weights = weights)
> 
> texreg::screenreg(match_model_2b)
> 
> 
> 
> #Non govt PGM 
> matched_3b <- matchit(lag_not_govt_pgm ~ v2x_polyarchy +
>                         gdppc +
>                         log_milex +
>                         log_rents +
>                         rugged +
>                         total_size +
>                         peace_years +
>                         post_cw,
>                       data = match_data,
>                       method = "full")
> 
> 
> summary(matched_3b)
> 
> matched_3b_data <- match.data(matched_3b)
> 
> match_model_3b <- glm(cw_onset ~ lag_not_govt_pgm, 
>                       data = matched_3b_data,
>                       weights = weights)
> 
> texreg::screenreg(match_model_3b)
> 
> # Calculate predicted probabilities
> pred_probs3b <- predict(match_model_3b, type = "response")
> 
> # Calculate predicted change in probability for lag_presence
> pr_change3b <- margins(match_model_3b, variables = "lag_not_govt_pgm")
> 
> # Print results
> summary(pr_change3b)
> 
> 
> #Creating tables from the matching analysis
> 
> match_model_list_2 <- list(
>   match_model_1b,
>   match_model_2b,
>   match_model_3b
> )
> 
> htmlreg(match_model_list_2,
>         custom.model.names = c("Model 1", "Model 2", "Model 3"),
>         custom.coef.names = c("intercept",
>                               "PGM Presence (t-1)",
>                               "Gov't Formed PGM Presence (t-1)",
>                               "Non-Gov't PGM Presence (t-1)"),
>         custom.coef.map = list(
>           "lag_presence" = "PGM Presence (t-1)",
>           "lag_govt_pgm" = "Gov't Formed PGM Presence (t-1)",
>           "lag_not_govt_pgm" = "Non-Gov't PGM Presence (t-1)"),
>         custom.note = "Note: The Dependent Variable for Each Model is Civil Conflict Onset, 
>         Observations are weighted by propensity scores",
>         intercept = FALSE, 
>         file = "pgm_cw_matching_full.html",
>         color = "black",
>         caption = "",
>         digits = 3
> )
> 
> 
> 
> 
> 
> 

========================================================================= 
Log End Time: 2025-01-15 10:17:09.183199 
Log Elapsed Time: 0 00:01:01 
========================================================================= 
